﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using QuocTeViet.BL;
using QuocTeViet.DO;

namespace QuocTeViet.AdminCP.PageUC
{
    public partial class ucListProductUnit : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            gvDonViTinhDataSource();
        }

        protected void gvDonViTinhDataSource()
        {
            gvDonViTinh.DataSource = new cmsDonViBL().SelectAll();
            gvDonViTinh.DataBind();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("Default.aspx?Page=ProductUnit");
        }


        protected void gvDonViTinh_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            new cmsDonViBL().Delete(new cmsDonViDO { DonViID = Convert.ToInt32(gvDonViTinh.DataKeys[e.RowIndex].Value) });
            Functions.Alert("Xóa bản ghi thành công", Request.Url.ToString());
        }

        protected void gvDonViTinh_SelectedIndexChanged(object sender, EventArgs e)
        {
            int DonViID = int.Parse(gvDonViTinh.DataKeys[gvDonViTinh.SelectedIndex].Value.ToString());
            Response.Redirect("Default.aspx?Page=ProductUnit&ProductUnitID=" + DonViID.ToString());
        }

        protected void gvDonViTinh_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvDonViTinh.PageIndex = e.NewPageIndex;
            gvDonViTinhDataSource();
        }
    }
}